package com.ruoyi.project.card.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.framework.aspectj.lang.annotation.Anonymous;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.card.domain.AlumniArticle;
import com.ruoyi.project.card.service.IAlumniArticleService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 校园新闻Controller
 *
 * @author hongwj
 * @date 2024-05-03
 */
@RestController
@RequestMapping("/card/article" )
@Slf4j
public class AlumniArticleController extends BaseController {
    @Autowired
    private IAlumniArticleService alumniArticleService;

    /**
     * 查询校园新闻列表
     */
    @GetMapping("/list" )
    @Anonymous
    public TableDataInfo list(AlumniArticle alumniArticle) {
        startPage();
        List<AlumniArticle> list = alumniArticleService.selectAlumniArticleList(alumniArticle);
        return getDataTable(list);
    }

    /**
     * 查询所有校园新闻列表
     */
    @Log(title = "校园新闻" , businessType = BusinessType.OTHER)
    @GetMapping("/all/articles" )
    @Anonymous
    public AjaxResult all(AlumniArticle alumniArticle) {
        List<AlumniArticle> list = alumniArticleService.selectAlumniArticleList(alumniArticle);
        return success(list);
    }

    /**
     * 导出校园新闻列表
     */
    @Log(title = "校园新闻" , businessType = BusinessType.EXPORT)
    @PostMapping("/export" )
    public void export(HttpServletResponse response, AlumniArticle alumniArticle) {
        List<AlumniArticle> list = alumniArticleService.selectAlumniArticleList(alumniArticle);
        ExcelUtil<AlumniArticle> util = new ExcelUtil<AlumniArticle>(AlumniArticle. class);
        util.exportExcel(response, list, "校园新闻数据" );
    }

    /**
     * 获取校园新闻详细信息
     */
    @GetMapping(value = "/{id}" )
    @Anonymous
    public AjaxResult getInfo(@PathVariable("id" ) Long id) {
        return success(alumniArticleService.selectAlumniArticleById(id));
    }

    /**
     * 新增校园新闻
     */
    @Log(title = "校园新闻" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AlumniArticle alumniArticle) {
        return toAjax(alumniArticleService.insertAlumniArticle(alumniArticle));
    }

    /**
     * 修改校园新闻
     */
    @Log(title = "校园新闻" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AlumniArticle alumniArticle) {
        return toAjax(alumniArticleService.updateAlumniArticle(alumniArticle));
    }

    /**
     * 删除校园新闻
     */
    @Log(title = "校园新闻" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}" )
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(alumniArticleService.deleteAlumniArticleByIds(ids));
    }
}
